#ifndef _COMPONENT_H_
#define _COMPONENT_H_

#include "Message.h"

#include <memory>
#include <Util/Uitl.h>

namespace Engine2D
{
    class IObject;

    struct Component : public std::enable_shared_from_this<Component>
    {
        virtual ~Component() = default;
        virtual void OnTick(IObject*) {}
        virtual void OnInit(IObject*) {}
        virtual void OnMessage(Message*) {}
    };

    template<typename Component, typename... Components>
    struct ComponentGroup {};
    
    template<typename Component, typename... Components>
    constexpr int GroupSize(ComponentGroup<Component, Components...>)
    {
        return sizeof...(Components) + 1;
    }

    template<typename F, typename Component, typename... Components>
    void ForeachComponents(F && fn, ComponentGroup<Component, Components...>)
    {
        fn(Component());
        if constexpr (sizeof...(Components) != 0) {
            ComponentGroup<Components...> group;
            ForeachComponents(std::forward<F>(fn), group);
        }
    }
} // namespace Engine2D


#endif